

#ifndef __FILE_LIST_H__
#define __FILE_LIST_H__


#include "debug.h"
#include "include_other.h"
#include "include_com.h"


#include "list.h"
#include "quick_sort.h"


#define MAX_FILE_NUMBER	(100000)



#define MAX_FILE_NAME_SIZE				1024
#define MAX_DIR_NAME_SIZE				MAX_FILE_NAME_SIZE
#define FULL_PATH_SIZE					(MAX_DIR_NAME_SIZE + MAX_FILE_NAME_SIZE + 1)

#define  RET_FAILURE    (-1)
#define  RET_SUCCESS    (0)


typedef enum
{ 
	F_DIR =	0,
	F_UNKOWN =	1,
	F_BMP =	2,
	F_MP3 =	3,
	F_JPG =	5,
	F_TXT =	7,
	F_BYE1 =	11,
	F_OGG = 13,
	F_MPG = 17,
	F_MPEG = 19,
	F_FLC = 29,
	F_WAV = 31,
	F_PCM = 37,

	F_ALL=	255,
}FileType; //valid types arranged be alphabet



typedef enum{
	MEDIA_FILE_TYPE_VIDEO,
	MEDIA_FILE_TYPE_MUSIC,
	MEDIA_FILE_TYPE_PHOTO,	
	MEDIA_FILE_TYPE_TXT,
	MEDIA_FILE_TYPE_COUNT,
}media_type_tt;


typedef enum
{
	MUSIC_FILE_LIST,
	IMAGE_FILE_LIST,
	VIDEO_FILE_LIST,
	
	VIDEO_PHOTO_FILE_LIST,
	
	VIDEO_PHOTO_MUSIC_FILE_LIST,
	
	DIR_FILE_LIST,
	RAW_FILE_LIST,
	DLNA_FILE_LIST,

	MEDIA_PLAYER_FILE_LIST_NUMBER,
}FileListType;

typedef enum
{
	SORT_RAND=0,
	SORT_NAME, 
	SORT_DATE,
	SORT_SIZE,
	SORT_FAV,
}FileListSortType;


typedef struct
{
	char				name[MAX_FILE_NAME_SIZE];
	char				path[MAX_DIR_NAME_SIZE];
	FileType			filetype;
	char				in_play_list;
	unsigned int		size;
}FileInfo, *pFileInfo;	//info for ui show


typedef struct
{
	struct list_head	listpointer;
	
	FileType			type;	//file type

	unsigned int		size;
	
	unsigned char		attr; //file attribution
	unsigned int		time; //last modify time, hour(5b)<<11 |miniter(6b)<<5 |sec(5b)
	unsigned short	date; //(year-1980)(7b)<<9 | month(4b)<<5 | day(5b)

	char				in_play_list;
	char				dirpath[128];
	union
	{
		struct
		{
			unsigned int	size; //file size
		}
		FileExt;

		struct
		{
			unsigned short	dirnum;	//sub-dirnum under the dir
			unsigned short	filenum;	//filenum under the dir
		}
		DirExt;
		
	}ExtInfo;
	
	char name[0]; //must locate at the end of this structure
}FileListItem, *pFileListItem;



typedef struct
{
	struct list_head				listpointer;

	FileListType					type;	//filelist media type
	
	char							*dirpath; //dir's full name that the filelist belongs to

	unsigned short				dirnum;	//not include dir "..\"!!
	unsigned short				filenum;

	FileListSortType				sorttype;
	unsigned char					sortorder;//0:little order,!0:big order
	
	unsigned short				pic_filenum;
	unsigned short  				*pic_list;
	int							current_pic_count;	
	unsigned short				music_filenum;
	unsigned short				*music_list;
	int							current_music_count;	
	unsigned short				video_filenum;
	unsigned short				*video_list;
	int							current_video_count;    
		
	struct list_head				head;
}FileList, *pFileList;

typedef struct
{
	int					id_check_playlist;
	FileListSortType	mode;
}FileListCompareContext, *pFileListCompareContext;


typedef void* FileListHandle;




int strcmp_c(const char *s1, const char *s2);
void file_get_fullname(char *fullname,char *path, char *name);
int file_list_trim(FileListHandle handle, char* dirpath);
void file_list_clean(pFileList pfile_list);
void file_list_print(pFileList pfile_list);
pFileListItem	get_file_list_item_by_index(pFileList pfile_list, unsigned short index);
int compare_filelist_items(struct list_head *p1, struct list_head *p2, struct CompareParameter *p_para);
FileListHandle file_list_create(FileListType type);
void file_list_delete(FileListHandle handle);
FileType file_map_type(FileListType list_type, char *ext_name);
int file_list_read_folder(FileListHandle handle, char *dirpath);
int file_list_read_all_file(FileListHandle handle, char *dirpath,int check);
int file_list_sort(FileListHandle handle, FileListSortType sort_type);
int file_list_get_info(FileListHandle handle, unsigned int *dir_number, unsigned int *file_number, char* current_path);
int file_list_get_file(FileListHandle handle, unsigned short index, pFileInfo pinfo);









#endif

